﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using eCompany.eObj;
using eCompany.eManager;
namespace TestConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //create_new_company(@"..\..\xml\company3.xml");
            //initCurrency(@"..\..\xml\currency.xml");
            refreshCurrency(@"..\..\xml\currency.xml");
            //job(@"..\..\xml\company3.xml");
        }

        static void refreshCurrency(string filename)
        {
            eManager eM = new eManager();

            currency_list cl = new currency_list();

            eM.loadFile(filename, ref cl);

            eM.refreshCurrencies(ref cl,null);

            eM.saveFile(filename, cl);
        }
        static void initCurrency(string filename)
        {
            currency_list cl = new currency_list();

            currency c = new currency();
            c.short_name = "FRF";
            currency_value cv = new currency_value();
            cv.date = DateTime.Now;
            cv.value = 0.03;
            c.values_list.Add(cv);
            cl.currencies.Add(c);

            c = new currency();
            c.short_name = "SKK";
            cv = new currency_value();
            cv.date = DateTime.Now;
            cv.value = 0.024;
            c.values_list.Add(cv);
            cl.currencies.Add(c);

            eManager eM = new eManager();
            eM.saveFile(filename, cl);
            
        }

        static void job(string filename)
        {
            eManager eM = new eManager();
            organisation org = new organisation() ;
            
            eM.loadFile(filename, ref org);

            //employee e = eM.getEmployee(org, Guid.Parse("4f3a28b3-e3f1-4a32-93cf-7cd91bda0576"));
            employee e = eM.getEmployee(org, "Whilefork");
            //company c = eM.getCompany(org, Guid.Parse("09a475d4-b916-44a4-97b4-e49d32095dad"));
            company c = eM.getCompany(org, "Whilecorp Food Company");

            eM.buyMaterials(c, material_type_enum.Grain, 1000, 0.05);

            eM.workEmployee(c, e,DateTime.Today, 8, 330/*, 430*/);

            double ms = eM.getStockCount(c);
            eM.addToShop(c, "FRF", 100, 1);
            ms = eM.getStockCount(c);
            double mv = eM.getStockValue(c);
            double mc = eM.getMaterialCount(c, material_type_enum.Grain);
            //eM.sellShop(c, "FRF", 10);
            eM.removeFromShop(c, "FRF");

            eM.saveFile(filename, org);

        }

        static void create_new_company(string filename)
        {
            organisation org = new organisation();
            
            company c1 = new company();
            c1.name = "Whilecorp Food Company";
            c1.id = Guid.NewGuid().ToString();
            c1.type = company_type_enum.food;

            material_stock ms = new material_stock();
            ms.material_type = material_type_enum.Grain;
            ms.materials = new List<material>();
            c1.material_list.Add(ms);

            account a1 = new account();
            a1.currency = "FRF";
            a1.id = Guid.NewGuid().ToString();
            a1.name = "Account FRF";
            c1.default_account = a1.id;
            c1.account_list.Add(a1);

            account a2 = new account();
            a2.currency = "SKK";
            a2.id = Guid.NewGuid().ToString();
            a2.name = "Account SKK";
            c1.account_list.Add(a2);

            employee e1 = new employee();
            e1.id = Guid.NewGuid().ToString();
            e1.name = "Whilefork";
            e1.date_in = DateTime.Now;

            salary s1 = new salary();
            s1.date = DateTime.Now;
            s1.value = 1.27;
            e1.salary_list.Add(s1);
            c1.employee_list.Add(e1);
            org.company_list.Add(c1);

            eManager eM = new eManager();
            eM.saveFile(filename, org);
        }
    }
}
